package my.graduation.result;

import lombok.Data;
import lombok.NoArgsConstructor;
import my.graduation.enums.HttpCodeEnums;

import java.io.Serializable;

/**
 * @Author: RavenLyn
 * @Date: 2024-11-26
 */
@Data
public class Result<T> implements Serializable {
    private int code; // 状态码 成功返回 1 失败返回 0
    private String msg; // 消息描述
    private T data; // 返回的数据

    // 静态方法，用于创建成功或失败的响应
    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 200;
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.data = data;
        result.code = 200;
        return result;
    }

    public static <T> Result<T> error(HttpCodeEnums enums) {
        Result<T> result = new Result<T>();
        result.msg = enums.getMessage();
        result.code = enums.getCode();
        return result;
    }
}
